#include "positionarray.h"

PositionArray::PositionArray(QObject *parent):QObject(parent)
{}

PositionArray::PositionArray(const PositionArray & u)
{
	for(int i=0;i<u._valueVector.size();++i)
	{
		Position* newvalue = new Position(*(u._valueVector.at(i)));
		_valueVector.push_back(newvalue);
	}
}

PositionArray::~PositionArray()
{
	clear();
}

void PositionArray::addValue(Position* value)
{
	_valueVector.push_back(value);
}

void PositionArray::removeValueByIndex(int index)
{
	delete _valueVector.at(index);
	_valueVector[index] = NULL;
	_valueVector.remove(index);
}

int PositionArray::indexOf(Position* value)
{
	for(int i=0;i<_valueVector.size();++i)
	{
		if(_valueVector.at(i)->getPositionX() == value->getPositionX()
			&& _valueVector.at(i)->getPositionY() == value->getPositionY())
		{
			return i;
		}
	}
	return _valueVector.size();
}

void PositionArray::clear()
{
	for(int i=0;i<_valueVector.size();++i)
	{
		delete _valueVector.at(i);
		_valueVector[i] = NULL;
	}
	_valueVector.clear();
}

int PositionArray::size()
{
	return _valueVector.size();
}